/**
 * HelloRequest.java
 */
package fss.common.communication;

import java.util.ArrayList;
import java.util.List;

import fss.util.rmi.RmiId;

/**
 * A 'ping' request.
 * <p>
 * A ping has to have an originator and can go to one or all remote 
 * object(s) registered at the Service Registry, including the Service
 * Registry.
 * 
 * @author thinh
 *
 */
public class PingRequest implements Request {
    private static final long serialVersionUID = 1L;
    /**
     * An array to keep the information logs.
     */
    private ArrayList<String> info = new ArrayList<String>();
    /**
     * An array to keep the error logs.
     */
    private ArrayList<String> error = new ArrayList<String>(); 
    /**
     * The personalized message of this message.
     */
    private String message = null;
    /**
     * The identifier of the originator of this message.
     */
    private RmiId sourceId = null;
    /**
     * The destination id.
     */
    private RmiId destinationId = null;
    /**
     * The recipient list.
     */
    private List<RmiId> recipientList = null;
    /**
     * Create the request from the source id.
     * @param sourceId the id.
     */
    public PingRequest(RmiId sourceId) {
        this.sourceId = sourceId;
        recipientList = new ArrayList<RmiId>();
    }
    /**
     * Create a request for the specified destination id.
     * @param sourceId the source id.
     * @param destinationId the destination id.
     */
    public PingRequest(RmiId sourceId, RmiId destinationId) {
        this(sourceId);
        this.destinationId = destinationId;
    }
    /**
     * Get the destination id.
     * @return the id.
     */
    public RmiId getDestinationId() {
        return destinationId;
    }
    /**
     * Set the destination id.
     * @param destinationId the id.
     */
    public void setDestinationId(RmiId destinationId) {
        this.destinationId = destinationId;
    }
    @Override
    public void addLog(String msg) {
        info.add(msg);
    }
    @Override
    public void addError(String err) {
        error.add(err);
    }
    @Override
    public List<String> getLogs() {
        return info;
    }
    @Override
    public List<String> getErrors() {
        return error;
    }
    @Override
    public RmiId getSource() {
        return sourceId;
    }
    /**
     * Get the personalized message.
     * @return the message, or null if not set.
     */
    public String getMessage() {
        return message;
    }
    /**
     * Set the personalized message.
     * @param message the message.
     */
    public void setMessage(String message) {
        this.message = message;
    }
    @Override
    public RmiId getDestination() {
        return destinationId;
    }
    @Override
    public List<RmiId> getRecipientList() {
        return recipientList;
    }
    @Override
    public void addRecipientList(RmiId recipient) {
        if(recipientList == null) recipientList = new ArrayList<RmiId>();
        recipientList.add(recipient);
    }
}
